<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="incluir_form_ato" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('config.xhtml')}" value="Configurações" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexAto.xhtml')}" value="Ato" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar Ato" update="@form" immediate="true"/>
                </div>
                <p:panel header="Criar Ato">
                    <p:messages id="msg"/>
                    <fieldset>
                        <legend>Ato</legend> 
                        <h:panelGrid columns="1" id="panelAll" width="950" >
                            <h:panelGrid columns="2" id="panel"  styleClass="textAlignRight" columnClasses="textAlignRight"> 

                                <h:outputLabel  value="Ato Tipo :" />
                                <p:autoComplete id="atotipo_ato" effect="blind" value="#{managerAto.atoItem.atoTipo}" scrollHeight="200" completeMethod="#{managerAtoTipo.completeAtoTipo}"  
                                                size="45" var="p" itemLabel="#{p.descricao}" itemValue="#{p}" converter="atoTipoConverter" forceSelection="true" converterMessage="Erro, verifique o Fornecedor" 
                                                minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Ato Tipo' é obrigatório"> 
                                    <p:ajax event="itemSelect" listener="#{managerAto.handleSelect}"/>                                        
                                </p:autoComplete>

                                <h:outputLabel value="Código :"/>
                                <p:inputText value="#{managerAto.atoItem.codigo}" required="true" requiredMessage="O campo Código deve ser Preenchido"/>

                                <h:outputLabel value="Descrição :"/>
                                <p:inputTextarea  value="#{managerAto.atoItem.descricao}" cols="90"/>

                                <h:outputLabel value="Selo :"/>
                                <p:autoComplete id="tipoSelo" effect="blind" value="#{managerAto.atoItem.tipoSelo}" 
                                                completeMethod="#{managerTipoSelo.completeTipoSelo}"  
                                                size="45" var="p" itemLabel="#{p.nome}" itemValue="#{p}" 
                                                converter="tipoSeloConverter" forceSelection="true"
                                                converterMessage="Erro, verifique o Tipo Selo" minQueryLength="3"
                                                dropdown="true" > 
                                    <!--required="true" requiredMessage="O campo 'Tipo Selo' é obrigato"-->
                                    <p:ajax event="itemSelect" listener="#{managerAto.handleSelectTipoSelo}"/>
                                    <p:column>  
                                        <table >
                                            <tr  style="height:20px; background-color: \##{p.corSelo.cor};">
                                                <td style="width: 20px;"></td>
                                            </tr>
                                        </table>
                                    </p:column>
                                    <p:column>  
                                        #{p.nome}
                                    </p:column>  
                                </p:autoComplete>
                                <h:outputLabel value="Sigla:"/>
                                <p:inputText value="#{managerAto.atoItem.sigla}"/>
                                <h:outputLabel value="Prazo (Dias):"/>
                                <p:inputText value="#{managerAto.atoItem.prazo}"/>
                                <h:outputLabel value="Ato Campo :"/>
                               
                               
                             <p:column headerText="Campos">
                                    
                                    <p:pickList id="picklistAtoCampo" style="margin-top: 10px" value="#{managerAto.dualAtoCampo}" var="atoCampo"
                                                itemLabel="#{atoCampo.nome}" converter="atoCampoConverter" itemValue="#{atoCampo}">
                                        <f:facet name="sourceCaption">Campos</f:facet>	
                                        <f:facet name="targetCaption">Campos Selecionados</f:facet>
                                    </p:pickList>
                                    
                                </p:column>
                            </h:panelGrid>
                            <p:row>
                                <center>
                                    <br/>  
                                    <p:commandButton value="Adicionar"   actionListener="#{managerAto.addList()}" process="@this, panel" update="atoItemTable, msg, panel" />
                                    <p:commandButton value="Limpar"  icon="ui-icon-close"  actionListener="#{managerAto.limpaList()}" process="@this"  update="@form" immediate="true" />
                                    <br/>
                                </center>
                            </p:row>
                            <br/>
                            
                   
                            <p:dataTable var="item" id="atoItemTable" 
                                         value="#{managerAto.listAtoItem}"
                                         rowIndexVar="rowid" emptyMessage="Nenhum Item Ato Cadastrado">  
                                <f:facet name="header">  
                                    Lista de Atos
                                </f:facet>  
                                <p:column headerText="Codigo" style="width:60px" >  
                                    <h:outputText value="#{item.codigo}" style="float: right;"/>  
                                </p:column>
                                <p:column headerText="Descrição" >  
                                    <h:outputText value="#{item.descricao}" />  
                                </p:column>
                                <p:column headerText="Tabela" style="text-align: center;">  
                                    <h:outputText value="#{item.atoTipo.descricao}" />  
                                </p:column>
                                <p:column headerText="Tipo Selo" style="text-align: center;">  
                                    <h:outputText value="#{item.tipoSelo.nome}" />  
                                </p:column>
                                <p:column headerText="Sigla" style="text-align: center;">  
                                    <h:outputText value="#{item.sigla}" />  
                                </p:column>
                                <p:column headerText="Prazo" style="text-align: center;">  
                                    <h:outputText value="#{item.prazo}" />  
                                </p:column>
<!--                                <p:column headerText="Campos do Ato" style="text-align: center;">  
                                    <h:outputText value="{item.atoCampos}" />  
                                </p:column>-->

                                <p:column headerText="Opc" style="width: 43px">  
                                    <p:commandButton  style="width: 20px; height: 20px;" onclick="editRC({param:#{rowid}})" icon="editar"/>
                                    <p:commandButton  style="width: 20px; height: 20px;" onclick="removeRC({param:#{rowid}})" icon="ui-icon-trash"/>

                                </p:column>

                            </p:dataTable>
                            <p:remoteCommand name="editRC"
                                             update="atoItemTable, panelAll, picklistAtoCampo" process="@this" actionListener="#{managerAto.editList()}">
                            </p:remoteCommand>
                            <p:remoteCommand name="removeRC"
                                             update="atoItemTable, panelAll" process="@this" actionListener="#{managerAto.remove()}">
                            </p:remoteCommand>

                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <center>
                        <p:commandButton icon="ui-icon-disk" value="Salvar" actionListener="#{managerAto.salvar()}" update="@form" process="@this"/>
                        <p:commandButton icon="ui-icon-arrowreturnthick-1-w" value="Cancelar" actionListener="#{managerVisualizarAtoItem.redirect('indexAto.xhtml')}" immediate="true"/>
                    </center>
                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>

</html>

